let oUser = document.querySelector('#inputEmail3')
let oPass = document.querySelector('#inputPassword3')
let oLogin = document.querySelector('.btn-default')
/* let oReMe = document.querySelector('.rememberMe') */

// 一进来就判断是否有记住我
if (localStorage.getItem('token') !== null) {
    location.href = '../html/index.html'
}

// 节流
var flag = true

function fn() {
    if (flag) { 
        pAjax({
            url: '../server/login.php',
            type: 'post',
            data: {
                username: oUser.value,
                password: oPass.value
            }
        }).then(function (res) {
            let json = JSON.parse(res)

            if (json.err === 0) {
                alert(json.msg)
                // 登陆成功
                // 存一个localStorage
                localStorage.setItem('token', '8923jsdsdk9sdhosj92ol2')
                // 记住我的状态
                //localStorage.setItem('checked', oReMe.checked)

                // 跳转到index
                location.href = '../html/index.html'
            } else {
                console.log(11);
                alert(json.msg)
                // 打开节流
                flag = true
            }
        })
    }
    flag = false
}

oPass.addEventListener('keydown', function (ev) {
    if (ev.keyCode === 13) {
        fn()
    }
})

oLogin.addEventListener('click', fn)


